define(
  'youa.module.app.adjust', [
    'zepto',
    'zepto.cookie',
    'http://a.tepin.com/activity/iface/youayun-2.0.js'
  ],
  function ($, $cookie) {

    window.connectApp = window.connectApp || function(protocol) {
      var iframe = document.createElement("iframe");
      var iframeStyle = document.createAttribute("style");
      var iframeSrc = document.createAttribute("src");

      iframeStyle.nodeValue = "display:none;width:0;height:0;";
      iframeSrc.nodeValue = protocol;
      iframe.setAttributeNode(iframeStyle);
      iframe.setAttributeNode(iframeSrc);
      document.body.appendChild(iframe);

      setTimeout(function () {
          document.body.removeChild(iframe);
      }, 250);
    };

    window.openNativeShareWin = function() {
      var param = [];
      param.push("share=weixin,wx");
      param.push("share_icon=" +encodeURIComponent("http://static3.tepin.hk/common/images/apple-touch-icon-precomposed.png"));

      param.push('share_message='+encodeURIComponent(window.getDescription));
      param.push('share_title='  +encodeURIComponent(window.title));
      param.push('share_link=' + encodeURIComponent(window.location.href));
      var protocol = 'haiwaigouapp://m.tepin.hk/native?name=callNativeShare&' + param.join('&');
      connectApp(protocol);
    }

    if (navigator.userAgent.toLowerCase().indexOf('youayun') > -1) {
      $('.app-load').hide();
      $('header').hide();
      $('.bottomNav').hide();

      try {
        var url = window.location.href;
        if (/http:\/\/m\.tepin\.hk\/activity\/\d+\.html/.test(url)) {
          var tag = $.fn.cookie('hwg_tag');
          var title = $('meta[name="description"]').attr('content');

          // 暂时进行关闭
          // openNativeShareWin();
          //
          // if (window.youayunapp && typeof window.youayunapp.callNativeActivityUrl == 'function') {
          //   window.youayunapp.callNativeActivityUrl(title, url, tag);
          // }
        }
      } catch (error) {

      }

      $('a').on('click', function (e) {
        e.preventDefault();

        var aurl = $(this).attr('href');
        if (/http:\/\/m\.tepin\.hk\/shop\/sp-(?:.+)\.html/.test(aurl)) {
          var code = aurl.replace(/http:\/\/m\.tepin\.hk\/shop\/sp-|\.html.+/g, '')
          var tag = $.fn.cookie('hwg_tag');

          if (window.youayun && typeof window.youayun.callAppGoodsDetails == 'function') {
            window.youayun.callAppGoodsDetails({ "goodscode": code });
          } else if (window.youayunapp && typeof window.youayunapp.callNativeGoodsDetails == 'function') {
            window.youayunapp.callNativeGoodsDetails(code, tag);
          }

          // 无需处理活动
          // } else if (/http:\/\/m\.tepin\.hk\/activity\/(?:.+)\.html/.test(aurl)) {
          //   var code aurl.replace(/http:\/\/m\.tepin\.hk\/activity\/|\.html.+/g, '')
          //   window.youayun.callAppActivity({"activityCode":code});

        } else {
          window.location.href = aurl;
        }
      });
    }
  });